#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
//int inti_global_value = 10;
//int uninti_global_value;

int g_val = 100;

int main(){

    pid_t id = fork();
    if(id == 0){
        //子进程
        int cnt = 5;
        while(1){
            printf("i am child, pid = %d, ppid = %d, g_val = %d, &g_val = %p\n", getpid(), getppid(), g_val, &g_val);
            if(cnt) cnt--;
            else{
                g_val = 200;
                printf("g_val 100 to 200\n");
            }
            sleep(1);
        }
    }else{
        while(1){
            printf("i am parent, pid = %d, ppid = %d, g_val = %d, &g_val = %p\n", getpid(), getppid(), g_val, &g_val);
            sleep(1);
        }
    }




//    //heap
//    char* str1 = malloc(100 * sizeof(char));
//    char* str2 = malloc(100 * sizeof(char));
//    char* str3 = malloc(100 * sizeof(char));
//    printf("str1 : %p\n", str1);
//    printf("str2 : %p\n", str2);
//    printf("str3 : %p\n", str3);
//
//    //stack
//    int x = 10;
//    int y = 10;
//    int z = 10;
//    printf("x : %p\n", &x);
//    printf("y : %p\n", &y);
//    printf("z : %p\n", &z);

//    char* str = "Hello World!";
//    printf("code : %p\n", main);
//    printf("const string: %p\n", str);
//    printf("inti global value: %p\n", &inti_global_value);
//    printf("uninti global value: %p\n", &uninti_global_value);
//    char* malloc_char = (char*)malloc(100 * sizeof(char));
//    printf("heap : %p\n", malloc_char);
//    int x = 10;
//    printf("stack : %p\n", &x);
    return 0;
}
